package com.example.xianji.activity;

import java.lang.reflect.Field;
import java.util.ArrayList;

import org.json.JSONException;
import org.json.JSONObject;

import com.example.xianji.Contant;
import com.example.xianji.XJApplication;
import com.example.xianji.R;
import com.example.xianji.adapter.BaiKe_Detail_Adapter;
import com.example.xianji.adapter.Same_Name_Adapter;
import com.example.xianji.bean.BaiKe_Detail_DuiXiang;
import com.example.xianji.bean.Same;
import com.example.xianji.constant.Constant;
import com.example.xianji.utils.DownLoadUtils;

import com.example.xianji.utils.sp.PreferenceEngine;
import com.example.xianji.widgets.MyGridView;
import com.example.xianji.widgets.MyListview;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;
import com.sina.weibo.sdk.api.BaseMediaObject;
import com.sina.weibo.sdk.api.WebpageObject;
import com.sina.weibo.sdk.api.WeiboMessage;
import com.sina.weibo.sdk.api.WeiboMultiMessage;
import com.sina.weibo.sdk.api.share.BaseResponse;
import com.sina.weibo.sdk.api.share.IWeiboHandler;
import com.sina.weibo.sdk.api.share.IWeiboShareAPI;
import com.sina.weibo.sdk.api.share.SendMessageToWeiboRequest;
import com.sina.weibo.sdk.api.share.SendMultiMessageToWeiboRequest;
import com.sina.weibo.sdk.api.share.WeiboShareSDK;
import com.sina.weibo.sdk.auth.Oauth2AccessToken;
import com.sina.weibo.sdk.auth.WeiboAuthListener;
import com.sina.weibo.sdk.auth.sso.SsoHandler;
import com.sina.weibo.sdk.constant.WBConstants;
import com.sina.weibo.sdk.exception.WeiboException;
import com.sina.weibo.sdk.utils.Utility;
import com.tencent.connect.common.Constants;
import com.tencent.connect.share.QQShare;
import com.tencent.mm.opensdk.modelmsg.SendMessageToWX;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
import com.tencent.mm.opensdk.modelmsg.WXWebpageObject;
import com.tencent.tauth.IUiListener;
import com.tencent.tauth.Tencent;
import com.tencent.tauth.UiError;

import android.os.Bundle;
import android.os.Handler;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.os.Message;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

public class Main_BaiKe_DetailActivity extends Activity implements
        OnClickListener, IWeiboHandler.Response {
    /********************* 百科详细页面 ****************************************/
    private RelativeLayout baike_detail_back, baike_detail_zan;
    private TextView baike_detail_title, baike_text_citiao_name,
            text_zan_number, text_share_number;
    private MyGridView baike_detail_mygridview;
    private ImageView baike_detail_zan_image, baike_detail_qq,
            baike_detail_xinglang, baike_detail_weixin;
    private ArrayList<Same> same_list = new ArrayList<Same>();
    private Same_Name_Adapter mSame_Name_Adapter;
    //    private SharedPreferences sp;
//    private Editor ed;
    private SsoHandler mSsoHandler;
    private boolean isInstalledWeibo;
    private int supportApiLevel;
    private IWeiboShareAPI mWeiboShareAPI = null;
    private Oauth2AccessToken mAccessToken;
    private String share_url;
    private MyListview baike_detail_listview;
    private ArrayList<BaiKe_Detail_DuiXiang> detail_list = new ArrayList<BaiKe_Detail_DuiXiang>();
    private BaiKe_Detail_Adapter mBaiKe_Detail_Adapter;
    private int count_praise;
    private DownLoadUtils mDownLoadUtils;
    public static ArrayList<Bitmap> bitmap_list = new ArrayList<Bitmap>();
    public static int baike_detail_id;// 百科详情页的id
    public static int share_count;// 分享转帖数
    private Handler handler = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (msg.what == 1) {
                // baike_detail_mygridview.setAdapter(mSame_Name_Adapter);
                // get_share_data();
                baike_detail_listview.setAdapter(mBaiKe_Detail_Adapter);
            }
        }

    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) {
            getWindow().addFlags(
                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            getWindow().addFlags(
                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }
        setContentView(R.layout.activity_main__bai_ke__detail);

        mDownLoadUtils = new DownLoadUtils();

        baike_detail_back = (RelativeLayout) findViewById(R.id.baike_detail_back);
        baike_detail_title = (TextView) findViewById(R.id.baike_detail_title);
        baike_text_citiao_name = (TextView) findViewById(R.id.baike_text_citiao_name);
        baike_detail_mygridview = (MyGridView) findViewById(R.id.baike_detail_mygridview);
        /*
         * baike_detail_gaishu_relative = (RelativeLayout)
         * findViewById(R.id.baike_detail_gaishu_relative);
         * baike_detail_gaishu_content = (TextView)
         * findViewById(R.id.baike_detail_gaishu_content);
         */
        baike_detail_zan = (RelativeLayout) findViewById(R.id.baike_detail_zan);
        baike_detail_zan_image = (ImageView) findViewById(R.id.baike_detail_zan_image);
        baike_detail_qq = (ImageView) findViewById(R.id.baike_detail_qq);
        baike_detail_xinglang = (ImageView) findViewById(R.id.baike_detail_xinglang);
        baike_detail_weixin = (ImageView) findViewById(R.id.baike_detail_weixin);
        text_zan_number = (TextView) findViewById(R.id.text_zan_number);
        text_share_number = (TextView) findViewById(R.id.text_share_number);

        baike_detail_listview = (MyListview) findViewById(R.id.baike_detail_listview);

        mBaiKe_Detail_Adapter = new BaiKe_Detail_Adapter(
                Main_BaiKe_DetailActivity.this, detail_list);

//        sp = getSharedPreferences("text", MODE_PRIVATE);
//        ed = sp.edit();
        /*
         * baike_detail_tongyici_one=(TextView)
         * findViewById(R.id.baike_detail_tongyici_one);
         * baike_detail_tongyici_two=(TextView)
         * findViewById(R.id.baike_detail_tongyici_two);
         * baike_detail_tongyici_three=(TextView)
         * findViewById(R.id.baike_detail_tongyici_three);
         */
        mSame_Name_Adapter = new Same_Name_Adapter(this, same_list);

        baike_detail_back.setOnClickListener(this);
        baike_detail_zan.setOnClickListener(this);
        baike_detail_qq.setOnClickListener(this);
        baike_detail_xinglang.setOnClickListener(this);
        baike_detail_weixin.setOnClickListener(this);

        XJApplication.cachThreadPool.execute(new Runnable() {

            @Override
            public void run() {
                get_baike_detail();
            }
        });

    }

    /**************** 获取百科详情 **********************************/
    public void get_baike_detail() {

        HttpUtils httpUtils = new HttpUtils();
        RequestParams parms = new RequestParams();

        parms.addBodyParameter("bid", getIntent()
                .getIntExtra("baike_detail", 0) + "");

        httpUtils.send(HttpMethod.POST, Contant.baike_detail, parms,
                new RequestCallBack<String>() {

                    @Override
                    public void onFailure(HttpException arg0, String arg1) {
                    }

                    @Override
                    public void onSuccess(ResponseInfo<String> arg0) {
                        try {
                            JSONObject OBJECT = new JSONObject(arg0.result);
                            if (OBJECT.getInt("status") == 1) {

                                JSONObject data_object = OBJECT
                                        .getJSONObject("data");
                                baike_detail_title.setText(data_object
                                        .getString("word_name"));
                                baike_text_citiao_name.setText(data_object
                                        .getString("word_name"));
                                Log.i("ssawwwwwqq",
                                        data_object.getJSONObject("likeword")
                                                .length() + "");
                                /*
                                 * JSONArray same_array = data_object
                                 * .getJSONArray("likeword"); for (int i = 0; i
                                 * < same_array.length(); i++) { JSONObject
                                 * same_object = same_array .getJSONObject(i);
                                 * Same mSame = new Same();
                                 * mSame.setBaike_wid(same_object
                                 * .getInt("baike_wid"));
                                 * mSame.setSame_word_name(same_object
                                 * .getString("same_word_name"));
                                 * same_list.add(mSame); }
                                 */
                                /******************* 点赞数 ***********************************/
                                count_praise = data_object
                                        .getInt("count_praise");
                                share_url = data_object.getString("share_url");
                                share_count = data_object
                                        .getInt("count_forward");
                                text_zan_number.setText(data_object
                                        .getInt("count_praise") + "");
                                text_share_number.setText(data_object
                                        .getInt("count_forward") + "");
                                if (data_object.getString("summary").length() > 0) {
                                    BaiKe_Detail_DuiXiang su_BaiKe_Detail_DuiXiang = new BaiKe_Detail_DuiXiang();
                                    su_BaiKe_Detail_DuiXiang
                                            .setDetail_name("概述");
                                    su_BaiKe_Detail_DuiXiang
                                            .setDetail_content(data_object
                                                    .getString("summary"));
                                    detail_list.add(su_BaiKe_Detail_DuiXiang);
                                }
                                if (data_object.getString("work_principle")
                                        .length() > 0) {
                                    BaiKe_Detail_DuiXiang wo_BaiKe_Detail_DuiXiang = new BaiKe_Detail_DuiXiang();
                                    wo_BaiKe_Detail_DuiXiang
                                            .setDetail_name("工作原理");
                                    wo_BaiKe_Detail_DuiXiang.setDetail_content(data_object
                                            .getString("work_principle"));
                                    detail_list.add(wo_BaiKe_Detail_DuiXiang);
                                }

                                if (data_object.getString("purpose").length() > 0) {
                                    BaiKe_Detail_DuiXiang pu_BaiKe_Detail_DuiXiang = new BaiKe_Detail_DuiXiang();
                                    pu_BaiKe_Detail_DuiXiang
                                            .setDetail_name("用途");
                                    pu_BaiKe_Detail_DuiXiang
                                            .setDetail_content(data_object
                                                    .getString("purpose"));
                                    detail_list.add(pu_BaiKe_Detail_DuiXiang);
                                }
                                if (data_object.getString("classify").length() > 0) {
                                    BaiKe_Detail_DuiXiang cl_BaiKe_Detail_DuiXiang = new BaiKe_Detail_DuiXiang();
                                    cl_BaiKe_Detail_DuiXiang
                                            .setDetail_name("分类");
                                    cl_BaiKe_Detail_DuiXiang
                                            .setDetail_content(data_object
                                                    .getString("classify"));
                                    detail_list.add(cl_BaiKe_Detail_DuiXiang);
                                }

                                if (data_object.getString("lectotype_guide")
                                        .length() > 0) {
                                    BaiKe_Detail_DuiXiang le_BaiKe_Detail_DuiXiang = new BaiKe_Detail_DuiXiang();
                                    le_BaiKe_Detail_DuiXiang
                                            .setDetail_name("选型指南");
                                    le_BaiKe_Detail_DuiXiang.setDetail_content(data_object
                                            .getString("lectotype_guide"));
                                    detail_list.add(le_BaiKe_Detail_DuiXiang);
                                }
                                if (data_object.getString("maintain").length() > 0) {
                                    BaiKe_Detail_DuiXiang ma_BaiKe_Detail_DuiXiang = new BaiKe_Detail_DuiXiang();
                                    ma_BaiKe_Detail_DuiXiang
                                            .setDetail_name("维护保养");
                                    ma_BaiKe_Detail_DuiXiang
                                            .setDetail_content(data_object
                                                    .getString("maintain"));
                                    detail_list.add(ma_BaiKe_Detail_DuiXiang);
                                }
                                /*
                                 * if(data_object.getString("maintain").length()>
                                 * 0){ BaiKe_Detail_DuiXiang
                                 * ma_BaiKe_Detail_DuiXiang=new
                                 * BaiKe_Detail_DuiXiang();
                                 * ma_BaiKe_Detail_DuiXiang
                                 * .setDetail_name("维护保养");
                                 * ma_BaiKe_Detail_DuiXiang
                                 * .setDetail_content(data_object
                                 * .getString("maintain"));
                                 * detail_list.add(ma_BaiKe_Detail_DuiXiang); }
                                 */
                                if (data_object.getString("matters_attention")
                                        .length() > 0) {
                                    BaiKe_Detail_DuiXiang mat_BaiKe_Detail_DuiXiang = new BaiKe_Detail_DuiXiang();
                                    mat_BaiKe_Detail_DuiXiang
                                            .setDetail_name("注意事项");
                                    mat_BaiKe_Detail_DuiXiang.setDetail_content(data_object
                                            .getString("matters_attention"));
                                    detail_list.add(mat_BaiKe_Detail_DuiXiang);
                                }

                                if (data_object.getString("trouble_shooting")
                                        .length() > 0) {
                                    BaiKe_Detail_DuiXiang tr_BaiKe_Detail_DuiXiang = new BaiKe_Detail_DuiXiang();
                                    tr_BaiKe_Detail_DuiXiang
                                            .setDetail_name("故障排除");
                                    tr_BaiKe_Detail_DuiXiang.setDetail_content(data_object
                                            .getString("trouble_shooting"));
                                    detail_list.add(tr_BaiKe_Detail_DuiXiang);
                                }
                                if (data_object.getString("application_scheme")
                                        .length() > 0) {
                                    BaiKe_Detail_DuiXiang mat_BaiKe_Detail_DuiXiang = new BaiKe_Detail_DuiXiang();
                                    mat_BaiKe_Detail_DuiXiang
                                            .setDetail_name("应用方案");
                                    mat_BaiKe_Detail_DuiXiang.setDetail_content(data_object
                                            .getString("application_scheme"));
                                    detail_list.add(mat_BaiKe_Detail_DuiXiang);
                                }
                                if (data_object.getString("brand_recommend")
                                        .length() > 0) {
                                    BaiKe_Detail_DuiXiang mat_BaiKe_Detail_DuiXiang = new BaiKe_Detail_DuiXiang();
                                    mat_BaiKe_Detail_DuiXiang
                                            .setDetail_name("品牌推荐");
                                    mat_BaiKe_Detail_DuiXiang.setDetail_content(data_object
                                            .getString("brand_recommend"));
                                    detail_list.add(mat_BaiKe_Detail_DuiXiang);
                                }

                                if (data_object.getString("product_recommend")
                                        .length() > 0) {
                                    BaiKe_Detail_DuiXiang mat_BaiKe_Detail_DuiXiang = new BaiKe_Detail_DuiXiang();
                                    mat_BaiKe_Detail_DuiXiang
                                            .setDetail_name("产品推荐");
                                    mat_BaiKe_Detail_DuiXiang.setDetail_content(data_object
                                            .getString("product_recommend"));
                                    detail_list.add(mat_BaiKe_Detail_DuiXiang);
                                }
                                handler.sendEmptyMessage(1);
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                });
    }

    /********************* 点赞数据请求 *************************/
    public void get_zan_data() {

        HttpUtils httpUtils = new HttpUtils();
        RequestParams parms = new RequestParams();
        parms.addBodyParameter("token", PreferenceEngine.getInstance().getString(Constant.SP.NAME, Constant.SP.KEY_XIANJI_TOKEN, ""));
        // 百科id
        parms.addBodyParameter("wid", getIntent().getIntExtra("baike_detail", 0) + "");
        httpUtils.send(HttpMethod.POST, Contant.baike_zan, parms,
                new RequestCallBack<String>() {

                    @Override
                    public void onFailure(HttpException arg0, String arg1) {
                    }

                    @Override
                    public void onSuccess(ResponseInfo<String> arg0) {
                        try {
                            JSONObject OBJECT = new JSONObject(arg0.result);
                            Toast.makeText(Main_BaiKe_DetailActivity.this,
                                    OBJECT.getString("msg"), Toast.LENGTH_SHORT).show();
                            if (OBJECT.getInt("status") == 1) {
                                baike_detail_zan_image
                                        .setImageResource(R.drawable.zan_lanse);
                                int plus_count_praise = count_praise + 1;
                                text_zan_number.setText(plus_count_praise + "");
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                });
    }

    /******************** 获取分享接口 *************************/
    public void get_share_data() {
        HttpUtils httpUtils = new HttpUtils();
        RequestParams parms = new RequestParams();
        parms.addBodyParameter("token", PreferenceEngine.getInstance().getString(Constant.SP.NAME, Constant.SP.KEY_XIANJI_TOKEN, ""));
        parms.addBodyParameter("wid", getIntent()
                .getIntExtra("baike_detail", 0) + "");// 百科id

        httpUtils.send(HttpMethod.POST, Contant.baike_share, parms,
                new RequestCallBack<String>() {

                    @Override
                    public void onFailure(HttpException arg0, String arg1) {
                    }

                    @Override
                    public void onSuccess(ResponseInfo<String> arg0) {
                        try {
                            JSONObject OBJECT = new JSONObject(arg0.result);
                            if (OBJECT.getInt("status") == 1) {
                                int new_share_count = share_count + 1;
                                text_share_number.setText(new_share_count + "");
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                });
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.baike_detail_back) {
            Main_BaiKe_DetailActivity.this.finish();
        } else if (v.getId() == R.id.baike_detail_zan) {
            if (PreferenceEngine.getInstance().getBoolean(Constant.SP.NAME, Constant.SP.KEY_XIANJI_DENGLU, false)) {
                get_zan_data();
            } else {
                Intent intent = new Intent(Main_BaiKe_DetailActivity.this,
                        Main_LoginActivity.class);
                startActivity(intent);
            }
        } else if (v.getId() == R.id.baike_detail_qq) {
            if (PreferenceEngine.getInstance().getBoolean(Constant.SP.NAME, Constant.SP.KEY_XIANJI_DENGLU, false)) {
                share_QQ_Qzon();
            } else {
                Intent intent = new Intent(Main_BaiKe_DetailActivity.this,
                        Main_LoginActivity.class);

                startActivity(intent);

            }

        } else if (v.getId() == R.id.baike_detail_xinglang) {
            if (PreferenceEngine.getInstance().getBoolean(Constant.SP.NAME, Constant.SP.KEY_XIANJI_DENGLU, false)) {
                WeiBo_share();
            } else {
                Intent intent = new Intent(Main_BaiKe_DetailActivity.this,
                        Main_LoginActivity.class);

                startActivity(intent);
            }

        } else if (v.getId() == R.id.baike_detail_weixin) {
            if (PreferenceEngine.getInstance().getBoolean(Constant.SP.NAME, Constant.SP.KEY_XIANJI_DENGLU, false)) {
                Contant.Click_WeiXin_Share = 1;
                baike_detail_id = getIntent().getIntExtra("baike_detail", 0);
                weiXin_prnyyouquan_showShare();
            } else {
                Intent intent = new Intent(Main_BaiKe_DetailActivity.this,
                        Main_LoginActivity.class);

                startActivity(intent);
            }

        }
    }

    /**
     * 微信朋友圈
     */
    private void weiXin_prnyyouquan_showShare() {

        SendMessageToWX.Req req = new SendMessageToWX.Req();
        req.scene = SendMessageToWX.Req.WXSceneTimeline;

        req.transaction = buildTransaction("webpage");
        req.message = new WXMediaMessage();

        req.message.title = baike_text_citiao_name.getText().toString();

        req.message.mediaObject = new WXWebpageObject(share_url);

        XJApplication.getApi().sendReq(req);

    }

    private String buildTransaction(final String type) {
        return (type == null) ? String.valueOf(System.currentTimeMillis())
                : type + System.currentTimeMillis();
    }

    /******************* 分享qq空间 *********************************/
    public void share_QQ_Qzon() {

        final Bundle params = new Bundle();
        params.putInt(QQShare.SHARE_TO_QQ_EXT_INT,
                QQShare.SHARE_TO_QQ_FLAG_QZONE_AUTO_OPEN);
        params.putString(QQShare.SHARE_TO_QQ_TITLE, "贤集网");
        params.putString(QQShare.SHARE_TO_QQ_SUMMARY, baike_text_citiao_name
                .getText().toString());
        params.putString(QQShare.SHARE_TO_QQ_TARGET_URL, share_url);

        params.putString(QQShare.SHARE_TO_QQ_APP_NAME, "贤集网");

        XJApplication.getTencent().shareToQQ(Main_BaiKe_DetailActivity.this,
                params, new QQShareListener());

    }

    /***************** QQ分享的回调 *************************/
    private class QQShareListener implements IUiListener {

        @Override
        public void onComplete(Object arg0) {
            Toast.makeText(Main_BaiKe_DetailActivity.this, "分享成功", Toast.LENGTH_SHORT).show();
            XJApplication.cachThreadPool.execute(new Runnable() {

                @Override
                public void run() {
                    get_share_data();
                }
            });
        }

        @Override
        public void onError(UiError arg0) {
            Toast.makeText(Main_BaiKe_DetailActivity.this, arg0 + "", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onCancel() {
            Toast.makeText(Main_BaiKe_DetailActivity.this, "取消", Toast.LENGTH_SHORT).show();
        }
    }

    /*************************** 新浪微博分享 ************************************/
    private void WeiBo_share() {
        mSsoHandler = new SsoHandler(Main_BaiKe_DetailActivity.this,
                XJApplication.mAuthInfo);

        mSsoHandler.authorizeClientSso(new AuthListener());

        mWeiboShareAPI = WeiboShareSDK.createWeiboAPI(
                Main_BaiKe_DetailActivity.this, "4216978203");

        mWeiboShareAPI.registerApp();

        isInstalledWeibo = mWeiboShareAPI.isWeiboAppInstalled();
        supportApiLevel = mWeiboShareAPI.getWeiboAppSupportAPI();

        mWeiboShareAPI.handleWeiboResponse(getIntent(),
                Main_BaiKe_DetailActivity.this);

    }

    class AuthListener implements WeiboAuthListener {

        @Override
        public void onComplete(Bundle values) {
            try {

                //try   catch   解决 调用这个对象出现空指针异常 （兼容问题）
                mAccessToken = Oauth2AccessToken.parseAccessToken(values);

                String phoneNum = mAccessToken.getPhoneNum();
                if (mAccessToken.isSessionValid()) {

                    if (isInstalledWeibo) {
                        if (mWeiboShareAPI.isWeiboAppSupportAPI()) {
                            if (supportApiLevel >= 10351 /*
                             * ApiUtils.BUILD_INT_VER_2_2
                             */) {

                                WeiboMultiMessage weiboMessage = new WeiboMultiMessage();

                                weiboMessage.mediaObject = getWebpageObj();

                                SendMultiMessageToWeiboRequest request = new SendMultiMessageToWeiboRequest();

                                request.transaction = String.valueOf(System
                                        .currentTimeMillis());
                                request.multiMessage = weiboMessage;

                                mWeiboShareAPI.sendRequest(
                                        Main_BaiKe_DetailActivity.this, request);
                            } else {

                                WeiboMessage weiboMessage = new WeiboMessage();

                                weiboMessage.mediaObject = getWebpageObj();

                                SendMessageToWeiboRequest request = new SendMessageToWeiboRequest();

                                request.transaction = String.valueOf(System
                                        .currentTimeMillis());
                                request.message = weiboMessage;

                                mWeiboShareAPI.sendRequest(
                                        Main_BaiKe_DetailActivity.this, request);
                            }
                        }

                    }

                    Log.i("dddddddd", mAccessToken + "");
                    Toast.makeText(Main_BaiKe_DetailActivity.this, "授权成功",
                            Toast.LENGTH_SHORT).show();

                } else {

                    String code = values.getString("code");

                    Toast.makeText(Main_BaiKe_DetailActivity.this, "授权失败",
                            Toast.LENGTH_LONG).show();
                }
            } catch (Exception e) {
            }
        }

        @Override
        public void onCancel() {
            Toast.makeText(Main_BaiKe_DetailActivity.this, "取消",
                    Toast.LENGTH_LONG).show();
        }

        @Override
        public void onWeiboException(WeiboException e) {
            Toast.makeText(Main_BaiKe_DetailActivity.this,
                    "Auth exception : " + e.getMessage(), Toast.LENGTH_LONG)
                    .show();
        }
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);

        mWeiboShareAPI.handleWeiboResponse(intent,
                Main_BaiKe_DetailActivity.this);
    }

    /********************** 新浪微博的回调接口 *****************************************/
    @Override
    public void onResponse(BaseResponse baseResp) {
        if (baseResp != null) {
            switch (baseResp.errCode) {
                case WBConstants.ErrorCode.ERR_OK:
                    XJApplication.cachThreadPool.execute(new Runnable() {

                        @Override
                        public void run() {
                            get_share_data();
                        }
                    });

                    Toast.makeText(this, "成功", Toast.LENGTH_LONG).show();
                    break;
                case WBConstants.ErrorCode.ERR_CANCEL:
                    Toast.makeText(this, "取消", Toast.LENGTH_LONG).show();
                    break;
                case WBConstants.ErrorCode.ERR_FAIL:
                    Toast.makeText(this, "Error Message: " + baseResp.errMsg,
                            Toast.LENGTH_LONG).show();
                    break;
            }
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        // SSO 授权回调
        // 重要：发起 SSO 登陆的 Activity 必须重写 onActivityResults
        if (mSsoHandler != null) {
            mSsoHandler.authorizeCallBack(requestCode, resultCode, data);
        }
        /****************************** QQ 分享 必须加的，回调不起作用 ********************************/
        // 官方文档没这句代码, 但是很很很重要, 不然不会回调!
        Tencent.onActivityResultData(requestCode, resultCode, data,
                new QQShareListener());

        if (requestCode == Constants.REQUEST_API) {
            if (resultCode == Constants.REQUEST_QQ_SHARE
                    || resultCode == Constants.REQUEST_QZONE_SHARE
                    || resultCode == Constants.REQUEST_OLD_SHARE) {
                Tencent.handleResultData(data, new QQShareListener());
            }
        }

    }

    private BaseMediaObject getWebpageObj() {
        WebpageObject mediaObject = new WebpageObject();
        mediaObject.identify = Utility.generateGUID();
        mediaObject.title = baike_text_citiao_name.getText().toString();
        mediaObject.description = "贤集网" + share_url;

        Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
                R.drawable.touxiang);
        mediaObject.setThumbImage(bitmap);
        mediaObject.actionUrl = share_url;
        mediaObject.defaultText = "";
        return mediaObject;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        /*************************** isCancle 可以关闭流，控制数据的加载避免多个线程的堵塞 ***********************************/
        mDownLoadUtils.setCancle(true);

        // cachThreadPool.shutdownNow();
        for (int i = 0; i < bitmap_list.size(); i++) {
            if (!bitmap_list.get(i).isRecycled() && bitmap_list.get(i) != null) {
                bitmap_list.get(i).recycle();
                System.gc();
            }
        }
        handler.removeCallbacksAndMessages(null);

    }
}
